using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace HHF.Models
{ 
    public class VolunteerApplicationViewModelRepository : IVolunteerApplicationViewModelRepository
    {
        HhfDbContext context = new HhfDbContext();

        public IQueryable<VolunteerApplicationViewModel> All
        {
            get { return context.VolunteerApplicationViewModels; }
        }

        public IQueryable<VolunteerApplicationViewModel> AllIncluding(params Expression<Func<VolunteerApplicationViewModel, object>>[] includeProperties)
        {
            IQueryable<VolunteerApplicationViewModel> query = context.VolunteerApplicationViewModels;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public VolunteerApplicationViewModel Find(int id)
        {
            return context.VolunteerApplicationViewModels.Find(id);
        }

        public void InsertOrUpdate(VolunteerApplicationViewModel volunteerapplicationviewmodel)
        {
            if (volunteerapplicationviewmodel.Id == default(int)) {
                // New entity
                context.VolunteerApplicationViewModels.Add(volunteerapplicationviewmodel);
            } else {
                // Existing entity
                context.Entry(volunteerapplicationviewmodel).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var volunteerapplicationviewmodel = context.VolunteerApplicationViewModels.Find(id);
            context.VolunteerApplicationViewModels.Remove(volunteerapplicationviewmodel);
        }

        public void Save()
        {
            context.SaveChanges();
        }
    }

    public interface IVolunteerApplicationViewModelRepository
    {
        IQueryable<VolunteerApplicationViewModel> All { get; }
        IQueryable<VolunteerApplicationViewModel> AllIncluding(params Expression<Func<VolunteerApplicationViewModel, object>>[] includeProperties);
        VolunteerApplicationViewModel Find(int id);
        void InsertOrUpdate(VolunteerApplicationViewModel volunteerapplicationviewmodel);
        void Delete(int id);
        void Save();
    }
}